let ipt = document.getElementById("ipt");
let list = document.getElementById("list");
ipt.oninput = function () {
    var script = document.createElement("script");
    var url = "https://www.baidu.com/sugrec?";
    url += "prod=pc";
    url += "&from=pc_web";
    url += "&wd=" + ipt.value;
    url += "&cb=callback"

    script.src = url;
    document.body.appendChild(script);
    script.onload = function () {
        script.remove();
    }
}

$("#ipt")
.focus(function(){ $("#list").show() })
.blur(function(){ $("#list").hide() })


function callback(data) {
    if (!data.g) {
        return list.innerHTML = ""
    }
    list.innerHTML = data.g.map(item => `<li>${item.q}</li>`).join("");
}

//删除记录
$(function(){
    function init(){
        $(".delete1").click(function(){$(this).parent().parent().hide()})
        $(".delete2").click(function(){$(this).parent().parent().hide()})
    }
    init()
})